package http_proxy_middleware

import (
	"gitee.com/zhoulvvv/my_go_gateway/middleware"
	"gitee.com/zhoulvvv/my_go_gateway/public"
	"gitee.com/zhoulvvv/my_go_gateway/services"
	"github.com/gin-gonic/gin"
	"log"
)

// 匹配接入方式，基于请求信息
func HTTPAccessModeMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		service, err := services.ServiceManagerServiceHandler.HTTPAccessMode(c)
		if err != nil {
			middleware.ResponseError(c, 1001, err)
			c.Abort() // 终止请求
			return
		}
		log.Printf("匹配到的服务信息 %s\n", public.ObjToJson(service))
		// 存储到上下文
		c.Set("service", service)
		c.Next()
	}
}
